﻿using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using System.Data.Entity.Repository.Filters;
using Testing.DataService.Entities;
using Testing.DataService.Mock;
using Testing.DataService.Repositories;
using Testing.IntegrationTests.Filters;
using System.Diagnostics;

namespace Testing.UnitTests
{
    [TestClass]
    public class FilterPerformanceTesting
    {
        [TestMethod]
        public void IQueryable_FilterBasic_EntityNumber_1()
        {
            Stopwatch sw = new Stopwatch();

            RegisterableFilter filter = new RegisterableFilter
            {
                FilterInstance = new ProductFilterNumber2(),
                ParameterBag = null
            };
            QueryableFilterManager.Register(filter);

            IQueryable<Product> products = new MockProduct()
                .CreateMultipleProducts(1);

            List<Product> filterdVouchers;

            sw.Start();
            {
                var entities = products.AsQueryable();

                var toFilteredResult = entities.FilterWith<IProductFilter, Product>();

                filterdVouchers = toFilteredResult.ToList();
            }
            sw.Stop();

            //breakepoint here
            TimeSpan duration = sw.Elapsed;

            Assert.IsNotNull(filterdVouchers, duration.ToString());
        }

        [TestMethod]
        public void IQueryable_FilterBasic_EntityNumber_5000()
        {
            Stopwatch sw = new Stopwatch();

            RegisterableFilter filter = new RegisterableFilter
            {
                FilterInstance = new ProductFilterNumber2(),
                ParameterBag = null
            };
            QueryableFilterManager.Register(filter);

            IQueryable<Product> products = new MockProduct()
                .CreateMultipleProducts(5000);

            List<Product> filterdVouchers;

            sw.Start();
            {
                var entities = products.AsQueryable();

                var toFilteredResult = entities.FilterWith<IProductFilter, Product>();

                filterdVouchers = toFilteredResult.ToList();
            }
            sw.Stop();

            //breakepoint here
            TimeSpan duration = sw.Elapsed;

            Assert.IsNotNull(filterdVouchers, duration.ToString());
        }


        [TestMethod]
        public void IQueryable_FilterBasic_EntityNumber_50000()
        {
            Stopwatch sw = new Stopwatch();

            RegisterableFilter filter = new RegisterableFilter
            {
                FilterInstance = new ProductFilterNumber2(),
                ParameterBag = null
            };
            QueryableFilterManager.Register(filter);

            IQueryable<Product> products = new MockProduct()
                .CreateMultipleProducts(50000);

            List<Product> filterdVouchers;

            sw.Start();
            {
                var entities = products.AsQueryable();

                var toFilteredResult = entities.FilterWith<IProductFilter, Product>();

                filterdVouchers = toFilteredResult.ToList();
            }
            sw.Stop();

            //breakepoint here
            TimeSpan duration = sw.Elapsed;

            Assert.IsNotNull(filterdVouchers, duration.ToString());
        }

        [TestCleanup]
        public void TestCleanup()
        {
            QueryableFilterManager.ClearFilters();
        }

    }
}
